from core.support import set_cutscene
from core.item import Item
from core.action import Action

class MagicKnife(Item):
    def __init__(self):
        Item.__init__(self, "magic_knife")    # do basic initialization for every item
        self.is_out = False
        
        # build list of actions
        self.add_action(UseMagicKnife)
        self.add_action(SheatheMagicKnife)
    
    def get_description(self):
        if self.is_out:
            return "magic knife (on your hand)"
        else:
            return "magic knife (sheathed)"

# define actions for this item

class UseMagicKnife(Action):
    def __init__(self):
        Action.__init__(self, "use_magic_knife")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Use magic knife"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # enabled only if knife is in.
    def is_enabled(self):
        if self.item.is_out:
            return False
        else:
            return True
        
    # get knife out and add cutscene
    def do_action(self,game,room,request):
        self.item.is_out = True
        set_cutscene("You take the magic knife on your left hand.")
        return
    
class SheatheMagicKnife(Action):
    def __init__(self):
        Action.__init__(self, "sheathe_magic_knife")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Sheathe Magic Knife"

    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"    
    
    # enabled only if lamp is out.
    def is_enabled(self):
        if self.item.is_out:
            return True
        else:
            return False
        
    # get knife in and add cutscene
    def do_action(self,game,room,request):
        self.item.is_out = False
        set_cutscene("You put your magic knife back in its sheath.")
        return
    